package com.example._003configtest.config;

import com.example._003configtest.annotation.ConditionalCustom;
import com.example._003configtest.mybean.MyBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// proxyBeanMethods = true  :单例模式,保证每个@Bean方法被调用多少次返回的组件都是同一个
// proxyBeanMethods = false :原型模式，每个@Bean方法被调用多少次返回的组件都是新创建的
@Configuration(proxyBeanMethods = true)
//仅当com.mysql.cj.jdbc.Driver类存在时该配置类生效
//@ConditionalOnClass(name = "com.mysql.cj.jdbc.Driver")
public class MyConfigTest {
    @Bean
//    @ConditionalOnProperty(name="test",havingValue = "foo",prefix = "com.example._003configtest")
//    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
    //当user.active表达式为true时，该方法才会生效
//    @ConditionalOnExpression("user.active")
    //只有当org.test1,org.test2两个配置属性都存在时才生效
    @ConditionalCustom({"org.test1","org.test2"})
    public MyBean myBean(){
        return new MyBean();
    }
}
